#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool checkInclusion(string s1, string s2) {
        unordered_map<char, int> hash;
        int len = s1.size();
        for (auto c : s1) hash[c]++;
        int left = 0, right = 0, n = s2.size();
        while (right < n)
        {
            while (right < n && --hash[s2[right++]] >= 0) --len;
            if (len == 0) return true;
            while (left < right && ++hash[s2[left++]] > 0) ++len;
        }
        return false;
    }
};